package com.my.db;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

/**
 * @author timo 2021/3/5
 */
//https://www.jianshu.com/p/217ccb986290
//    加载顺序
@Configuration
//@Order(-2147483648)
//@AutoConfigureOrder(-2147483648)
//@PropertySource("classpath:/defal-db.yml")
@PropertySource( ignoreResourceNotFound = true,encoding = "UTF-8" ,value = "classpath:/defal-db.yml",factory = YamlConfigFactory.class)
@PropertySource( ignoreResourceNotFound = true,encoding = "UTF-8" ,value = "classpath:defal-db.properties")
@Slf4j
//jpa
@EntityScan("com.my.db.test") //不在一个项目中需要配置
@EnableJpaRepositories(basePackages = { "com.my.db.test" }) //这个是jpa repository的包的路径
@ComponentScan(basePackages = "com.my.db.test")
public class DbConfiguration {
    public DbConfiguration() {
      log.info("配置数据源");
    }


    // 创建事务管理器 -- 处理多数据源情况下使用DataSourceTransactionManager的问题
//原文链接：https://blog.csdn.net/qq_41419769/article/details/120306506
    //2.在原添加事务（@Transactional）处指定事务管理器
    //@Transactional(transactionManager = "transactionManager")
//    @Bean(name = "platformTransactionManager")
//    public PlatformTransactionManager txManager(@Qualifier("dataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }


//
//    @Bean
//    public Employee employee() {
//        return new Employee();
//    }
//
//    @Bean
//    public EmployeeJpa employeeJpa() {
//        return new EmployeeJpa();
//    }
//
//    @Bean
//    public EmployeeJpaService employeeJpaService() {
//        return new EmployeeJpaService();
//    }
//
//    @Bean
//    public EmployeeController employeeController() {
//        return new EmployeeController();
//    }
//    @Bean
//    public EmployeeJpaController employeeJpaController() {
//        return new EmployeeJpaController();
//    }
}
